'use strict'

var inherits = require('inherits')

var PropertiesActivator = require('../../PropertiesActivator')

var processProps = require('./parts/ProcessProps')
var eventProps = require('./parts/EventProps')
var linkProps = require('./parts/LinkProps')
var documentationProps = require('./parts/DocumentationProps')
var idProps = require('./parts/IdProps')
var nameProps = require('./parts/NameProps')
var executableProps = require('./parts/ExecutableProps')

function createGeneralTabGroups(
  element, canvas, bpmnFactory,
  elementRegistry, translate) {
  var generalGroup = {
    id: 'general',
    label: translate('General'),
    entries: []
  }
  idProps(generalGroup, element, translate)
  nameProps(generalGroup, element, bpmnFactory, canvas, translate)
  processProps(generalGroup, element, translate)
  executableProps(generalGroup, element, translate)

  var detailsGroup = {
    id: 'details',
    label: translate('Details'),
    entries: []
  }
  linkProps(detailsGroup, element, translate)
  eventProps(detailsGroup, element, bpmnFactory, elementRegistry, translate)

  var documentationGroup = {
    id: 'documentation',
    label: translate('Documentation'),
    entries: []
  }

  documentationProps(documentationGroup, element, bpmnFactory, translate)

  return [
    generalGroup,
    detailsGroup,
    documentationGroup
  ]
}

function BpmnPropertiesProvider(
  eventBus, canvas, bpmnFactory, elementRegistry, translate) {
  PropertiesActivator.call(this, eventBus)

  this.getTabs = function(element) {
    var generalTab = {
      id: 'general',
      label: translate('General'),
      groups: createGeneralTabGroups(
        element, canvas, bpmnFactory, elementRegistry, translate)
    }

    return [
      generalTab
    ]
  }
}

BpmnPropertiesProvider.$inject = [
  'eventBus',
  'canvas',
  'bpmnFactory',
  'elementRegistry',
  'translate'
]

inherits(BpmnPropertiesProvider, PropertiesActivator)

module.exports = BpmnPropertiesProvider
